package com.example.hxpc.guidancemanagement.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

import com.example.hxpc.guidancemanagement.R;
import com.example.hxpc.guidancemanagement.activity.ForgetPasswordActivity;
import com.example.hxpc.guidancemanagement.activity.MainActivity;
import com.example.hxpc.guidancemanagement.tools.LogoutT;
import com.example.hxpc.guidancemanagement.tools.ToastTools;

/**
 * Created by tao on 2017/11/26.
 * 登录页面的Frament
 */

public class LoginFrament extends Fragment implements View.OnClickListener{
    private View rootView;
    private EditText edt_phone , edt_pass;
    private TextView te_forget_pass;
    private Button bu_login , bu_tourist_login;
    private Intent intent;
    private CheckBox checkBox;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null){
            rootView = inflater.inflate(R.layout.frament_login,null);
        }
        initView(rootView);
        return rootView;
    }

    //初始化控件
    public void initView(View rootView){
        edt_phone = (EditText) rootView.findViewById(R.id.login_phone);
        edt_pass = (EditText) rootView.findViewById(R.id.login_pass);
        te_forget_pass = (TextView) rootView.findViewById(R.id.login_forget_pass);
        te_forget_pass.setOnClickListener(this);
        bu_login = (Button) rootView.findViewById(R.id.login);
        bu_login.setOnClickListener(this);
        bu_tourist_login = (Button) rootView.findViewById(R.id.tourist_login);
        bu_tourist_login.setOnClickListener(this);
        checkBox = (CheckBox) rootView.findViewById(R.id.check_box);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    ToastTools.toastMsg(getActivity(),"已选中");
                }else {
                    ToastTools.toastMsg(getActivity(),"没选中");
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login:
                break;
            case R.id.tourist_login:
                intent = new Intent(getActivity(), MainActivity.class);
                startActivity(intent);
                ToastTools.toastMsg(getActivity(),"您是游客");
                break;
            case R.id.login_forget_pass:
                Intent intent = new Intent(getActivity(), ForgetPasswordActivity.class);
                startActivity(intent);
                break;
        }
    }
}
